import type { PageInfo } from '@/interfaces/userManager'
const proTableFormat = (pageInfo: PageInfo<any>) => {
    const { list = [], pageNum = 1, total = 0 } = pageInfo || {}
    return {
        data: list,
        page: pageNum,
        total: total,
        success: true
    }
}

const sortTransform = (obj: { [key: string]: string | null }) => {
    const formatObj = {}
    for (let key in obj) {
        if (obj[key] === 'ascend') {
            formatObj[key] = 'asc'
        }
        if (obj[key] === 'descend') {
            formatObj[key] = 'desc'
        }
    }
    return formatObj
}

const formatImgsArr = (arr) => {
    // 明确指定 result 类型为 T[]
    let result: any[] = [];
    if (Array.isArray(arr)) {
        arr.forEach(item => {
            result = result.concat(item?.children || []);
        });
    }
    return result;
};
export {
    proTableFormat,
    sortTransform,
    formatImgsArr
}